package com.gaoqi.mq.config;

import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.DependsOn;

/**
 * 死信队列配置
 */
@Configuration
public class DeadLetterConfiguration {
    public static final String exchangeName = "dead_direct_exchange";
    public static final String queueName = "dead_direct_queue";
    public static final String routeKey = "dead";

    //死信声明交换机
    @Bean(name = "deadExchange")
    public Exchange getDeadExchange() {
        return new DirectExchange(exchangeName, true, false);
    }

    //声明死信队列
    @Bean(name = "deadQueue")
    public Queue getDeadQueue(){
        return new Queue(queueName,true,false,false);
    }

    //死信队列绑定死信交换机
    @Bean("bindDeadQueueAndExchange")
    public Binding deadQueueExchange(
            @Qualifier("deadExchange") Exchange deadExchange,
            @Qualifier("deadQueue") Queue deadQueue
    ){
        return BindingBuilder.bind(deadQueue).to(deadExchange).with(routeKey).noargs();
    }

}
